home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / src / GLperf3.12-src.lha / GLperf / ReadPix.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-01  |  8.6 KB  |  254 lines

  1. /*
  2.  * (c) Copyright 1995, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED
  4.  * Permission to use, copy, modify, and distribute this software for
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  *
  25.  * US Government Users Restricted Rights
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * Author: John Spitzer, SGI Applied Engineering
  36.  *
  37.  */
  38. #include <math.h>
  39. #include "ReadPix.h"
  40. #include "ReadPixX.h"
  41.  
  42. #undef offset
  43. #define offset(v) offsetof(ReadPixels,v)
  44.  
  45. static InfoItem ReadPixelsInfo[] = {
  46. #define INC_REASON INFO_ITEM_ARRAY
  47. #include "ReadPix.h"
  48. #undef INC_REASON
  49. };
  50. #include <malloc.h>
  51.  
  52. ReadPixelsPtr new_ReadPixels()
  53. {
  54.     ReadPixelsPtr this = (ReadPixelsPtr)malloc(sizeof(ReadPixels));
  55.  
  56.     ImagePtr thisImage = (ImagePtr)(&this->image_ReadPixels);
  57.     TransferMapPtr thisTransferMap = (TransferMapPtr)(&this->transfermap_ReadPixels);
  58.  
  59.     CheckMalloc(this);
  60.     new_Test((TestPtr)this);
  61.     new_Image(thisImage);
  62.     new_TransferMap(thisTransferMap);
  63.     SetDefaults((TestPtr)this, ReadPixelsInfo);
  64.     this->testType = ReadPixelsTest;
  65.     this->clearBefore = False;
  66.     this->subImage = False;
  67.     this->srcData = 0;
  68.     this->subImageData = 0;
  69.     this->imageData = 0;
  70.     this->usecPixelPrint = " microseconds per pixel with ReadPixels";
  71.     this->ratePixelPrint = " pixels per second with ReadPixels";
  72.     this->usecPrint = " microseconds per image with ReadPixels";
  73.     this->ratePrint = " ReadPixel images per second";
  74.     /* Set virtual functions */
  75.     this->SetState = ReadPixels__SetState;
  76.     this->delete = delete_ReadPixels;
  77.     this->Copy = ReadPixels__Copy;
  78.     this->Initialize = ReadPixels__Initialize;
  79.     this->Cleanup = ReadPixels__Cleanup;
  80.     this->SetExecuteFunc = ReadPixels__SetExecuteFunc;
  81.     this->PixelSize = ReadPixels__Size;
  82.     this->TimesRun = ReadPixels__TimesRun;
  83.     return this;
  84. }
  85.  
  86. void delete_ReadPixels(TestPtr thisTest)
  87. {
  88.     ReadPixelsPtr this = (ReadPixelsPtr)thisTest;
  89.     ImagePtr thisImage = (ImagePtr)(&this->image_ReadPixels);
  90.     TransferMapPtr thisTransferMap = (TransferMapPtr)(&this->transfermap_ReadPixels);
  91.  
  92.     delete_TransferMap(thisTransferMap);
  93.     delete_Image(thisImage);
  94.     delete_Test(thisTest);
  95. }
  96.  
  97. TestPtr ReadPixels__Copy(TestPtr thisTest)
  98. {
  99.     ReadPixelsPtr this = (ReadPixelsPtr)thisTest;
  100.     ReadPixelsPtr newReadPixels = new_ReadPixels();
  101.     FreeStrings((TestPtr)newReadPixels);
  102.     *newReadPixels = *this;
  103.     CopyStrings((TestPtr)newReadPixels, (TestPtr)this);
  104.     return (TestPtr)newReadPixels;
  105. }
  106.  
  107. void ReadPixels__Initialize(TestPtr thisTest)
  108. {
  109.     ReadPixelsPtr this = (ReadPixelsPtr)thisTest;
  110.     int windowDim = min(this->environ.windowWidth, this->environ.windowHeight);
  111.  
  112.     if (this->image_ReadPixels.imageWidth > windowDim)
  113.     this->image_ReadPixels.imageWidth = windowDim;
  114.     if (this->image_ReadPixels.imageHeight > windowDim)
  115.     this->image_ReadPixels.imageHeight = windowDim;
  116.  
  117.     /* Source image is imageWidth by imageHeight,
  118.      * The portion drawn by glReadPixels is readPixelsWidth by readPixelsHeight */
  119.     if (this->readPixelsWidth != -1) {
  120.     this->subImage = True;
  121.     } else {
  122.     this->readPixelsWidth = this->image_ReadPixels.imageWidth;
  123.     }
  124.     if (this->readPixelsHeight != -1) {
  125.     this->subImage = True;
  126.     } else {
  127.     this->readPixelsHeight = this->image_ReadPixels.imageHeight;
  128.     }
  129.  
  130.     /* Layout Source coordinates */
  131.     this->numDrawn = 0;
  132.     this->srcData = CreateSubImageData(windowDim, windowDim, 
  133.                           (float)this->readPixelsWidth, 
  134.                           (float)this->readPixelsHeight,
  135.                           1., 0., 0., Random, 0., this->readOrder==Spaced, 
  136.                           this->memAlignment, &this->numDrawn);
  137.  
  138.     ReadPixels__CreateImageData(this);
  139.  
  140.     /*
  141.      * Layout offsets in source image for subimage reads.
  142.      * All the subimages should lie entirely within the source image, so 100% of 
  143.      * our offsets should be "accepted".  numDrawn taken from Source layout above.
  144.      */
  145.     if (this->subImage) {
  146.     this->subImageData = CreateSubImageData(this->image_ReadPixels.imageWidth,
  147.                                  this->image_ReadPixels.imageHeight,
  148.                  this->readPixelsWidth,
  149.                  this->readPixelsHeight,
  150.                                  1., 0., 0., Random, 0., this->readOrder==Spaced,
  151.                                  this->memAlignment, &this->numDrawn);
  152.     }
  153.  
  154.     /*
  155.      * Draw something to discourage any sort of cheating (e.g. using calloc instead
  156.      * of reading the buffer)
  157.      */
  158.     Image__DrawSomething(this->environ.bufConfig.rgba, 
  159.                          this->environ.bufConfig.indexSize,
  160.                          this->environ.bufConfig.doubleBuffer);
  161. }
  162.  
  163. void ReadPixels__Cleanup(TestPtr thisTest)
  164. {
  165.     ReadPixelsPtr this = (ReadPixelsPtr)thisTest;
  166.     int i;
  167.  
  168.     if (this->srcData) AlignFree(this->srcData);
  169.     if (this->subImageData) AlignFree(this->subImageData);
  170.     if (this->imageData) {
  171.     void **imageDataPtr = this->imageData;
  172.         for (i = 0; i < this->numObjects; i++) AlignFree(*imageDataPtr++);
  173.     free(this->imageData);
  174.     }
  175. }
  176.  
  177. int ReadPixels__SetState(TestPtr thisTest)
  178. {
  179.     ReadPixelsPtr this = (ReadPixelsPtr)thisTest;
  180.     ImagePtr thisImage = (ImagePtr)(&this->image_ReadPixels);
  181.     TransferMapPtr thisTransferMap = (TransferMapPtr)(&this->transfermap_ReadPixels);
  182.  
  183.  
  184.     /* set parent state */
  185.     if (Test__SetState(thisTest) == -1) return -1;
  186.   
  187.  
  188.     /* set other inherited classes' states */
  189.     if (Image__SetState(thisImage) == -1) return -1;
  190.     if (TransferMap__SetState(thisTransferMap) == -1) return -1;
  191.  
  192.     /* set own state */
  193.  
  194.     return 0;
  195. }
  196.  
  197. void ReadPixels__SetExecuteFunc(TestPtr thisTest)
  198. {
  199.     ReadPixelsPtr this = (ReadPixelsPtr)thisTest;
  200.     ReadPixelsFunc function;
  201.  
  202.     function.word = 0;
  203.  
  204.     function.bits.functionPtrs = this->loopFuncPtrs;
  205.     function.bits.subimage = this->subImage;
  206.     function.bits.multiimage = (this->numObjects > 1);
  207.  
  208.     this->Execute = ReadPixelsExecuteTable[function.word];
  209. }
  210.  
  211. int ReadPixels__TimesRun(TestPtr thisTest)
  212. {
  213.     ReadPixelsPtr this = (ReadPixelsPtr)thisTest;
  214.     return this->numDrawn;
  215. }
  216.  
  217. float ReadPixels__Size(TestPtr thisTest)
  218. {
  219.     ReadPixelsPtr this = (ReadPixelsPtr)thisTest;
  220.  
  221.     return (float)(this->readPixelsWidth * this->readPixelsHeight);
  222. }
  223.  
  224. void ReadPixels__CreateImageData(ReadPixelsPtr this)
  225. {
  226.     int i;
  227.     void **imagePtr;
  228.     int imageSize;
  229.     void *image;
  230.  
  231.     this->imageData = (void**)malloc(sizeof(void*) * this->numObjects);
  232.     CheckMalloc(this->imageData);
  233.     imagePtr = this->imageData;
  234.     /*
  235.      * Need to allocate the correct amount of memory for the ReadPixels
  236.      * image.  To do this, we'll just let the image routine create an
  237.      * image with those attributes, then use that as our read buffer.
  238.      */
  239.     if (this->numObjects)
  240.     image = new_ImageData(
  241.                          this->image_ReadPixels.imageWidth,
  242.              this->image_ReadPixels.imageHeight,
  243.              this->image_ReadPixels.imageFormat,
  244.              this->image_ReadPixels.imageType,
  245.              this->image_ReadPixels.imageAlignment,
  246.              this->image_ReadPixels.imageSwapBytes,
  247.              this->image_ReadPixels.imageLSBFirst,
  248.              this->memAlignment,
  249.              &imageSize);
  250.     *imagePtr++ = image;
  251.     for (i = 1; i < this->numObjects; i++)
  252.     *imagePtr++ = AlignMalloc(imageSize, this->memAlignment);
  253. }
  254.